<?php
namespace App\Http\Controllers\Business\Admin\AppVersion;

use App\Models\AdminUser;
use App\Models\AppVersion;
use App\Models\Oss;
use Illuminate\Support\Facades\Auth;

class AppVersionManagement
{
    //app版本列表
    public static function appVersionList() {
        $data = AppVersion::where('created_at', '>=', '2016-07-01')->orderBy('created_at', 'desc')->get();
        return ['status'=>'success', 'data'=>$data];
    }
    //app 上传版本信息
    public static function appDownload($versionName,$versionCode, $type, $description, $originalName, $isForce) {
        if(!$versionCode||!$versionName||!$type||!$description) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $count = AppVersion::where('versionname', $versionName)->where('versioncode', $versionCode)
            ->where('type', $type)->get()->count();
        if($count > 0) {
            return ['status'=>'failed', 'message'=>'该版本已经存在'];
        }
//        if($originalName) {
//            $fileName = '../storage/qrcode/' . $originalName;
//            $filePath = 'upload/shop/'.time();
//            $ossResult = Oss::uploadFile($filePath, $fileName);
//            if(!$ossResult) {
//               return ['status'=>'failed', 'message'=>'上传文件失败'];
//            }
//            $url = 'upload/app/' . $originalName;
//        } else {
//            $url = '';
//        }

        $appVersion = AppVersion::create([
            'versionname' => $versionName,
            'versioncode' => $versionCode,
            'type' => $type,
            'description' => $description,
            'url' => $originalName,
            'isforce' => $isForce,
            'adminid' => Auth::guard('adminweb')->id()
        ]);
        $appVersion->save();
        return ['status'=>'success', 'message'=>'新增成功'];
    }
    //
}